
import { defineStore } from 'pinia'
import { requestBindEmail } from './setting.api'

export default defineStore('setting', {
    state: () => {
        return {
            dark_model: false,
        }
    },
    getters: {
        getDarkModel(): boolean {
            if(window.sessionStorage.getItem('dark_model') && (window.sessionStorage.getItem('dark_model') == 'true')) {
                this.dark_model = true
                return this.dark_model
            } else {
                this.dark_model = false
                return this.dark_model
            }
        }
    },
    actions: {
        bindEmail(data: Object) {
            return new Promise((resolve, reject) => {
                requestBindEmail(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
        setDarkModel(val: boolean) {
            this.dark_model = val
            window.sessionStorage.setItem('dark_model', JSON.stringify(val))
        }
    }
})
